package user

import (
	"github.com/gin-gonic/gin"
	"shejiao/base"
	common2 "shejiao/pkg/common"
	"shejiao/pkg/util"
)

var Match = &match{}

type match struct{}

// @summary 在线匹配
// @tags 匹配
// @Description 系统消息列表
// @Accept json
// @Produce json
// @Param token header string true "认证token"
// @Param   region  body  string  true  "匹配区域"
// @Router /api/user/match/run [post]
func (m match) Run(c *gin.Context) {
	var req struct {
		Region string `json:"region"`
	}
	err := c.ShouldBind(&req)
	if err != nil {
		common2.Response.Error(c, "未知区域", gin.H{})
		return
	}

	roleId := util.GetRoleId(c)
	actionId := base.UserMatchManagerRegion.Match(roleId, req.Region)
	if actionId == 0 {
		common2.Response.Error(c, "匹配失败", gin.H{})
		return
	}

	common2.Response.Success(c, gin.H{"user_id": actionId})
}
